//
//  customButton.m
//  BaseProject
//
//  Created by yang_0921 on 15/11/3.
//  Copyright © 2015年 Tarena. All rights reserved.
//

#import "customButton.h"

@implementation customButton

- (instancetype)initWithTitle:(NSString *)title image:(NSURL *)image
{
    self = [super init];
    if (self) {
        [self setTitle:title forState:UIControlStateNormal];
        [self setImageForState:UIControlStateNormal withURL:image];
    }
    return self;
}

- (instancetype)initWithTitle:(NSString *)title imageStr:(NSString *)imgStr
{
    self = [super init];
    if (self) {
        [self setTitle:title forState:UIControlStateNormal];
        [self setImage:[UIImage imageNamed:imgStr] forState:UIControlStateNormal];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.imageView.contentMode = UIViewContentModeCenter;
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        [self setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        self.titleLabel.font = [UIFont systemFontOfSize:14];
        self.adjustsImageWhenHighlighted = NO;
        
    }
    return self;
}



- (CGRect)imageRectForContentRect:(CGRect)contentRect{
    CGFloat imageW = 50;
    CGFloat imageH = 50;
    CGFloat imageX = (self.bounds.size.width - imageW) * 0.5;
    CGFloat imageY = 5;
    return CGRectMake(imageX, imageY, imageW, imageH);
}

- (CGRect)titleRectForContentRect:(CGRect)contentRect{
    CGFloat titleW = self.bounds.size.width;
    CGFloat titleH = 20;
    CGFloat titleX = 0;
    
    
    CGFloat titleY = CGRectGetMaxY(self.imageView.frame);//titleW - titleH - 4;
    return CGRectMake(titleX, titleY, titleW, titleH);
}

@end
